package com.jic.market.request.rest.discount;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.lang.StringUtils;

import javax.validation.Valid;
import javax.validation.ValidationException;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.math.BigDecimal;

/**
 * @author yinhaijun
 * @date: 2020/4/3
 */
@Data
public class PromotionGoods implements Serializable {

    private static final long serialVersionUID = -7834419059127921176L;

    @Valid
    @NotBlank(message = "商品编码不能为空")
    @ApiModelProperty(notes = "商品编码", required = true)
    private String thirdProductCode;

    @Valid
    @NotNull(message = "数量不能为空")
    @ApiModelProperty(notes = "数量", required = true)
    private Long num;

    // 购物车时不传，如果该商品是拼团商品，需要传入
    @ApiModelProperty(notes = "拼团活动编码", required = false)
    private String grouponPromotionCode;
    @ApiModelProperty(notes = "活动实例编码，参团必须传，开团的时候会返回", required = false)
    private String grouponInstCode;
    @ApiModelProperty(notes = "开参团flag  1 开团，0 参团", required = true)
    private Integer launchFlag;

    // 购物车不用传
    @ApiModelProperty(notes = "运费", required = false)
    private BigDecimal logisticsFee;

    public void check(){
        if(num == null || num <= 0){
            throw new ValidationException("商品数量必须大于0");
        }
        if(null != launchFlag && launchFlag.equals(0)){
            if(StringUtils.isBlank(grouponInstCode)){
                throw new ValidationException("参团时必须传活动实例编码");
            }
        }
    }

}
